/**
 *
 * @constructor
 */
function UrlObject()
{
	"use strict";

	/** @type {UrlObject} */
	var _this = this;
	/** @type {string} */
	var _path = window.location.pathname;       // /72157624472928513/4835546319
	/** @type {String} */
	var _basePath = null;
	/** @type {String} */
	this.setID = Enum.flickr.favoriteSet;
	/** @type {String} */
	this.photoID = null;

	function init()
	{
		var setMatch = /\/(\d{14,17})\/?(\d{10})?$/;
		var photoMatch = /\/(\d{10})\/?$/;

		if (setMatch.test(_path))
		{
			// show set and photo
			setMatch.lastIndex = 0;

			var matches = setMatch.exec(_path);

			_this.setID = matches[1];
			_this.photoID = (matches.length > 2) ? matches[2] : null;
			_this.normalize(setMatch);
		}
		else if (photoMatch.test(_path))
		{
			// show photo within set
			photoMatch.lastIndex = 0;
			_this.photoID = photoMatch.exec(_path)[1];
			_this.normalize(photoMatch);
		}
	}

	/**
	 * Update URL to reflect current set
	 * @return {UrlObject}
	 */
	this.update = function()
	{
		if (Session.set)
		{
			/** @type {Set} */
			var s = Session.set;
			/** @type {String} */
			var path = window.location.origin + _basePath + '/' + s.id;
			History.pushState(s.id, s.title, path);
		}
		return _this;
	};

	/**
	 * @return {Boolean}
	 */
	this.isEmpty = function()
	{
		return _this.photoID == null && _this.setID == Enum.flickr.favoriteSet;
	};

	/**
	 * @return {Boolean}
	 */
	this.hasPhotoOnly = function()
	{
		return _this.photoID != null && _this.setID == Enum.flickr.favoriteSet;
	};

	/**
	 * @return {Boolean}
	 */
	this.hasSet = function()
	{
		return _this.setID != Enum.flickr.favoriteSet && !Format.isEmpty(_this.setID);
	};

	/**
	 * @return {Boolean}
	 */
	this.hasPhotoAndSet = function()
	{
		return _this.photoID != null && _this.hasSet();
	};

	/**
	 * Normalize base path for subsequent URL rewriting
	 * @param {RegExp} pattern
	 */
	this.normalize = function(pattern) { _basePath = _path.replace(pattern, ''); };

	init();
}